package com.admin.business.background.venusOaApprovalRecord;

import com.tiangong.framework.annotation.OpenApi;
import com.tiangong.framework.bo.CDO;
import com.tiangong.framework.bo.Return;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @description: 请假补卡申请表
 * @create: 2023-11-04 17:26:21
 **/
@Service("venusOaApprovalRecordService")
@Slf4j
public class VenusOaApprovalRecordService{

    @Resource
    VenusOaApprovalRecordDao venusOaApprovalRecordDao;

    /**
     * 添加请假补卡申请表,获取id数据
     *
     * @param cdoRequest - id:主键
     *                   - org_id:总公司id
     *                   - user_id:操作人
     *                   - check_id:审批人
     *                   - approval_type:0.请假 1.补卡
     *                   - approval_detail_type:详细类型
     *                   - leave_begin_time:请假开始时间
     *                   - leave_end_time:请假结束时间
     *                   - repair_time:补卡时间
     *                   - clock_type:0.排班卡 1.值班卡
     *                   - clock_id:打卡id
     *                   - repair_id:补卡关联id  班次id  只限于排班有用
     *                   - reason:原因
     *                   - img_url:图片
     *                   - approval_state:0.待审批 1.通过 2拒绝  3.撤销
     *                   - check_user_id:审批人id(2023-01-12 增加跨级审批)
     *                   - check_remark:审批备注
     *                   - update_time:更新时间
     *                   - begin_time:开始时间
     *                   - state:是否删除：0、正常，1、已删除；
     * @return
     * @author Ht
     * @create: 2023-11-04 17:26:21
     */
    @OpenApi
    public Return addVenusOaApprovalRecord(CDO cdoRequest) {
        venusOaApprovalRecordDao.addVenusOaApprovalRecord(cdoRequest);
        CDO cdoResult = new CDO();
        if (cdoRequest.containsKey("id")) {
            cdoResult.set("id", cdoRequest.get("id"));
        }
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，更新请假补卡申请表数据
     *
     * @param cdoRequest - id:主键
     *                   - org_id:总公司id
     *                   - user_id:操作人
     *                   - check_id:审批人
     *                   - approval_type:0.请假 1.补卡
     *                   - approval_detail_type:详细类型
     *                   - leave_begin_time:请假开始时间
     *                   - leave_end_time:请假结束时间
     *                   - repair_time:补卡时间
     *                   - clock_type:0.排班卡 1.值班卡
     *                   - clock_id:打卡id
     *                   - repair_id:补卡关联id  班次id  只限于排班有用
     *                   - reason:原因
     *                   - img_url:图片
     *                   - approval_state:0.待审批 1.通过 2拒绝  3.撤销
     *                   - check_user_id:审批人id(2023-01-12 增加跨级审批)
     *                   - check_remark:审批备注
     *                   - update_time:更新时间
     *                   - begin_time:开始时间
     *                   - state:是否删除：0、正常，1、已删除；
     * @return
     * @author Ht
     * @create: 2023-11-04 17:26:21
     */
    @OpenApi
    public Return updateVenusOaApprovalRecordById(CDO cdoRequest) {
        venusOaApprovalRecordDao.updateVenusOaApprovalRecordById(cdoRequest);
        return Return.SUCCESS;
    }

    /**
     * 根据id，删除请假补卡申请表数据
     *
     * @param cdoRequest - id:主键
     * @return
     * @author Ht
     * @create: 2023-11-04 17:26:21
     */
    @OpenApi
    public Return deleteVenusOaApprovalRecordById(CDO cdoRequest){
        int count = venusOaApprovalRecordDao.deleteVenusOaApprovalRecordById(cdoRequest.getLong("id"));
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据条件，删除请假补卡申请表数据
     *
     * @param cdoRequest
     * @return
     * @author Ht
     * @create: 2023-11-04 17:26:21
     */
    @OpenApi
    public Return deleteVenusOaApprovalRecord(CDO cdoRequest) {
        int count = venusOaApprovalRecordDao.deleteVenusOaApprovalRecord(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据ID，获取请假补卡申请表数据
     *
     * @param cdoRequest - id:主键
     * @return
     * @author Ht
     * @create: 2023-11-04 17:26:21
     */
    @OpenApi
    public Return getVenusOaApprovalRecordById(CDO cdoRequest) {
        CDO cdoMapperResult = venusOaApprovalRecordDao.getVenusOaApprovalRecordById(cdoRequest.getLong("id"));
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据非空条件，获取请假补卡申请表数据列表
     *
     * @param cdoRequest
     * @return
     * @author Ht
     * @create: 2023-11-04 17:26:21
     */
    @OpenApi
    public Return getVenusOaApprovalRecordListPage(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusOaApprovalRecordDao.getVenusOaApprovalRecordListPage(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusOaApprovalRecordDao.getVenusOaApprovalRecordCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
    /**
     * 根据混合条件，获取请假补卡申请表数据列表
     *
     * @param cdoRequest - id:主键
     * @return
     * @author Ht
     * @create: 2023-11-04 17:26:21
     */
    @OpenApi
    public Return getVenusOaApprovalRecordListPageByCondition(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusOaApprovalRecordDao.getVenusOaApprovalRecordListPageByCondition(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusOaApprovalRecordDao.getVenusOaApprovalRecordCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
}
